﻿using System.Windows;
using System.Windows.Controls;

namespace AEM.Controls
{
    /// <summary>
    /// InLine.xaml 的交互逻辑
    /// </summary>
    public partial class InLine : UserControl
    {
        public InLine()
        {
            InitializeComponent();
        }

        private static void OnLiftNameChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            if (args.NewValue != args.OldValue)
            {
                (sender as InLine).lift_name.Text = args.NewValue as string;
            }
        }

        private static void OnLiftTypeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            if (args.NewValue != args.OldValue)
            {
                Style s = (Style)(sender as InLine).TryFindResource("lift_inline");
                switch ((Data.Enum.LiftType)args.NewValue)
                {
                    case Data.Enum.LiftType.电梯:
                        s = (Style)(sender as InLine).TryFindResource("lift_inline");
                        break;
                    case Data.Enum.LiftType.扶梯:
                        s = (Style)(sender as InLine).TryFindResource("escalator_inline");
                        break;
                    case Data.Enum.LiftType.人行步道:
                        s = (Style)(sender as InLine).TryFindResource("trails_inline");
                        break;
                }
                (sender as InLine).lift_type.Style = s;
            }
        }

        private static void OnLiftStatusChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            if (args.NewValue != args.OldValue)
            {
                Style s = (Style)(sender as InLine).TryFindResource("normal_inline");
                switch ((Data.Enum.LiftStatus)args.NewValue)
                {
                    case Data.Enum.LiftStatus.Fault:
                        s = (Style)(sender as InLine).TryFindResource("fault_inline");
                        break;
                    case Data.Enum.LiftStatus.Fire:
                        s = (Style)(sender as InLine).TryFindResource("fire_inline");
                        break;
                    case Data.Enum.LiftStatus.Driver:
                        s = (Style)(sender as InLine).TryFindResource("driver_inline");
                        break;
                    case Data.Enum.LiftStatus.Locked:
                        s = (Style)(sender as InLine).TryFindResource("locked_inline");
                        break;
                    case Data.Enum.LiftStatus.Overhaul:
                        s = (Style)(sender as InLine).TryFindResource("overhaul_inline");
                        break;
                    case Data.Enum.LiftStatus.NC:
                        s = (Style)(sender as InLine).TryFindResource("nc_inline");
                        break;
                    case Data.Enum.LiftStatus.Normal:
                    default:
                        s = (Style)(sender as InLine).TryFindResource("normal_inline");
                        break;
                }
                (sender as InLine).lift_status.Style = s;
            }
        }

        #region 注册属性
        /// <summary>
        /// 
        /// </summary>
        public static readonly DependencyProperty LiftNameProperty =
            DependencyProperty.Register("LiftName", typeof(string), typeof(InLine),
            new FrameworkPropertyMetadata("", new PropertyChangedCallback(OnLiftNameChanged)));

        /// <summary>
        /// 
        /// </summary>
        public string LiftName
        {
            get { return (string)GetValue(LiftNameProperty); }
            set { SetValue(LiftNameProperty, value); }
        }

        public static readonly DependencyProperty LiftTypeProperty =
            DependencyProperty.Register("LiftType", typeof(Data.Enum.LiftType), typeof(InLine),
            new FrameworkPropertyMetadata(Data.Enum.LiftType.电梯, new PropertyChangedCallback(OnLiftTypeChanged)));

        public Data.Enum.LiftType LiftType
        {
            get { return (Data.Enum.LiftType)GetValue(LiftTypeProperty); }
            set { SetValue(LiftTypeProperty, value); }
        }

        public static readonly DependencyProperty LiftStatusProperty =
            DependencyProperty.Register("LiftStatus", typeof(Data.Enum.LiftStatus), typeof(InLine),
            new FrameworkPropertyMetadata(Data.Enum.LiftStatus.Normal, new PropertyChangedCallback(OnLiftStatusChanged)));

        public Data.Enum.LiftStatus LiftStatus
        {
            get { return (Data.Enum.LiftStatus)GetValue(LiftStatusProperty); }
            set { SetValue(LiftStatusProperty, value); }
        }
        #endregion
    }

}
